package cn.kgc.vue.controller;

import cn.kgc.vue.annotation.LogAnnotation;
import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.commons.ResponseResult;
import cn.kgc.vue.entity.LogInfo;
import cn.kgc.vue.service.LogInfoService;
import cn.kgc.vue.enums.OperationType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@RestController
@RequestMapping("logs")
@Api(tags = "日志模块")
public class LogsController {
    @Resource
    private LogInfoService logInfoService;

    @PostMapping("logsPage")
    @ApiOperation("日志分页")
    public ResponseResult logsPage(@RequestBody QueryCondition<LogInfo> queryCondition) {
        return logInfoService.logsPage(queryCondition);
    }

    @LogAnnotation(model="日志模块",operation= OperationType.DELETE)
    @PostMapping("LogsDelete")
    @ApiOperation("删除日志")
    public ResponseResult LogsDelete(@RequestBody List<Integer> ids) {
        logInfoService.removeBatchByIds(ids);
        return ResponseResult.success().message("删除成功");
    }

  @PostMapping("exportLogs")
    @ApiOperation("批量导出")
    public ResponseResult exportLogs(@RequestBody LogInfo logInfo, HttpServletResponse response) throws IOException {
        return logInfoService.exportLogs(logInfo,response);
    }



}
